package com.sunshine.wrongquestionset.activity.exercise

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.sunshine.wrongquestionset.R
import com.sunshine.wrongquestionset.callback.OnClickListener
import kotlinx.android.synthetic.main.fragment_exercise_card.*

/**
 * 答题卡界面
 */
class ExerciseCardFragment : Fragment() {

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_exercise_card, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        recyclerView.adapter = ExerciseResultRecyclerAdapter(
            object : OnClickListener {
                override fun onClick(position: Int) {
                    //跳回到那道题目
                    (requireActivity() as ExerciseActivity).setViewPagerCurrentItem(position)
                }

                override fun onLongClick(position: Int) {

                }

            }
        )
    }

    /**
     * 通知做题情况更新
     */
    fun notifyDataSetChanged() {
        try {
            recyclerView.adapter?.notifyDataSetChanged()
        }catch (e: Exception) {

        }

    }
}